package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Random;

import org.testng.annotations.Test;

import com.example.utils.SortedListOf;

import static com.example.fw.ContactHelper.CREATION;

public class ContactModificationTests {

	public class RemovaAddressBook extends TestBase {

		@Test(dataProvider = "ramdomValidContactsGenerator")
		public void modificationContact(ContactDate contact) throws Exception {

			// save old state
			SortedListOf<ContactDate> oldList = app.getContactHelper()
					.getContacts();

			Random rnd = new Random();
			int index = rnd.nextInt(oldList.size() - 1);

			// actions
			app.getContactHelper().modifyContact(index, contact, CREATION);

			// save new state
			SortedListOf<ContactDate> newList = app.getContactHelper()
					.getContacts();

			// compare states
			assertThat(newList,
					equalTo(oldList.without(index).withAdded(contact)));

		}

	}
}
